package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.ConcreteBug;
import com.ruoyi.insurance.service.IConcreteBugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 详细漏洞Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/insurance/bug")
public class ConcreteBugController extends BaseController
{
    @Autowired
    private IConcreteBugService concreteBugService;

    /**
     * 查询详细漏洞列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConcreteBug concreteBug)
    {
        startPage();
        List<ConcreteBug> list = concreteBugService.selectConcreteBugList(concreteBug);
        return getDataTable(list);
    }

    /**
     * 导出详细漏洞列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:export')")
    @Log(title = "详细漏洞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConcreteBug concreteBug)
    {
        List<ConcreteBug> list = concreteBugService.selectConcreteBugList(concreteBug);
        ExcelUtil<ConcreteBug> util = new ExcelUtil<ConcreteBug>(ConcreteBug.class);
        util.exportExcel(response, list, "详细漏洞数据");
    }

    /**
     * 获取详细漏洞详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:query')")
    @GetMapping(value = "/{bugId}")
    public AjaxResult getInfo(@PathVariable("bugId") Long bugId)
    {
        return success(concreteBugService.selectConcreteBugByBugId(bugId));
    }

    /**
     * 新增详细漏洞
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:add')")
    @Log(title = "详细漏洞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConcreteBug concreteBug)
    {
        return toAjax(concreteBugService.insertConcreteBug(concreteBug));
    }

    /**
     * 修改详细漏洞
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:edit')")
    @Log(title = "详细漏洞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConcreteBug concreteBug)
    {
        return toAjax(concreteBugService.updateConcreteBug(concreteBug));
    }

    /**
     * 删除详细漏洞
     */
    @PreAuthorize("@ss.hasPermi('insurance:bug:remove')")
    @Log(title = "详细漏洞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bugIds}")
    public AjaxResult remove(@PathVariable Long[] bugIds)
    {
        return toAjax(concreteBugService.deleteConcreteBugByBugIds(bugIds));
    }
}
